package com.ltkj.baseplatform.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ltkj.baseplatform.mapper.SerAddressAreaMapper;
import com.ltkj.baseplatform.domain.SerAddressArea;
import com.ltkj.baseplatform.service.ISerAddressAreaService;

/**
 * 收货地址区域Service业务层处理
 * 
 * @author chenzeen
 * @date 2023-08-28
 */
@Service
public class SerAddressAreaServiceImpl implements ISerAddressAreaService 
{
    @Autowired
    private SerAddressAreaMapper serAddressAreaMapper;

    /**
     * 查询收货地址区域
     * 
     * @param id 收货地址区域主键
     * @return 收货地址区域
     */
    @Override
    public SerAddressArea selectSerAddressAreaById(Long id)
    {
        return serAddressAreaMapper.selectSerAddressAreaById(id);
    }

    /**
     * 查询收货地址区域列表
     * 
     * @param serAddressArea 收货地址区域
     * @return 收货地址区域
     */
    @Override
    public List<SerAddressArea> selectSerAddressAreaList(SerAddressArea serAddressArea)
    {
        return serAddressAreaMapper.selectSerAddressAreaList(serAddressArea);
    }

    /**
     * 新增收货地址区域
     * 
     * @param serAddressArea 收货地址区域
     * @return 结果
     */
    @Override
    public int insertSerAddressArea(SerAddressArea serAddressArea)
    {
        return serAddressAreaMapper.insertSerAddressArea(serAddressArea);
    }

    /**
     * 修改收货地址区域
     * 
     * @param serAddressArea 收货地址区域
     * @return 结果
     */
    @Override
    public int updateSerAddressArea(SerAddressArea serAddressArea)
    {
        return serAddressAreaMapper.updateSerAddressArea(serAddressArea);
    }

    /**
     * 批量删除收货地址区域
     * 
     * @param ids 需要删除的收货地址区域主键
     * @return 结果
     */
    @Override
    public int deleteSerAddressAreaByIds(Long[] ids)
    {
        return serAddressAreaMapper.deleteSerAddressAreaByIds(ids);
    }

    /**
     * 删除收货地址区域信息
     * 
     * @param id 收货地址区域主键
     * @return 结果
     */
    @Override
    public int deleteSerAddressAreaById(Long id)
    {
        return serAddressAreaMapper.deleteSerAddressAreaById(id);
    }

    @Override
    public Map<String, List<SerAddressArea>> getInitData() {
        Map<String, List<SerAddressArea>> result = new HashMap<String, List<SerAddressArea>>();
        SerAddressArea query = new SerAddressArea();
        query.setAreaStatus("0");
        query.setAreaLevel("1");
        List<SerAddressArea> proList = serAddressAreaMapper.selectSerAddressAreaList(query);

        SerAddressArea query2 = new SerAddressArea();
        query2.setpAreaCode(proList.get(0).getAreaCode());
        query2.setAreaStatus("0");
        List<SerAddressArea> cityList = serAddressAreaMapper.selectSerAddressAreaList(query2);

        SerAddressArea query3 = new SerAddressArea();
        query3.setpAreaCode(cityList.get(0).getAreaCode());
        query3.setAreaStatus("0");
        List<SerAddressArea> counList = serAddressAreaMapper.selectSerAddressAreaList(query3);

        result.put("level1", proList);
        result.put("level2", cityList);
        result.put("level3", counList);

        return result;
    }

    @Override
    public List<SerAddressArea> getNextAreaByCode(String areaCode) {
        SerAddressArea query = new SerAddressArea();
        query.setpAreaCode(areaCode);
        query.setAreaStatus("0");
        List<SerAddressArea> proList = serAddressAreaMapper.selectSerAddressAreaList(query);
        return proList;
    }
}
